package code.codeworld.common.kits;

import java.math.BigInteger;

/**
 * @Description: 分页工具
 * @Author: freecode
 * @Date: 2023/10/13 22:22
 * @version: 1.0
 */
public class PageUtil {


    /**
     * 获取分页[当前页，页总数]
     */
    public static Integer[] getPageNums(Integer[] pageNums) {
        //pageNums[pageNum,pageSize]
        if (pageNums[0] == null) {
            pageNums[0] = BigInteger.ZERO.intValue();
        } else {
            if (pageNums[0] <= BigInteger.ONE.intValue()) {
                pageNums[0] = BigInteger.ZERO.intValue();
            } else {
                pageNums[0] = pageNums[0] - BigInteger.ONE.intValue();
            }
        }
        if (pageNums[1] == null) {
            pageNums[1] = BigInteger.TEN.intValue();
        }
        return pageNums;
    }


    /**
     * 获取分页[起始条，结束条]
     */
    public static Integer[] getPageLimits(Integer[] pageLimits) {
        pageLimits = getPageNums(pageLimits);
        //pageLimits[offset,Limit]
        pageLimits[0] = pageLimits[0] * pageLimits[1];
        return pageLimits;
    }


}
